package model;
import java.util.HashMap;

/**
 * 
 * This class serves as a daily log for our application. Clients can add
 * foods or recipes to their intake, and can add exercises or workouts
 * to their list of performed activities. 
 * @author Roman Pusec, Dennis Goldfinger, Marko Bilic
 *
 */
public class DailyLog {
	
	private HashMap<Food, Integer> intake;
	private HashMap<Activity, Integer> exercisesPerformed;
	private double weight;
	private double limit;
	private String time;
	
	/**
	 * Constructor which sets the weight, limit, and time. 
	 * @param weight Weight. 
	 * @param limit Desired calorie limit.
	 * @param time The date of the log. 
	 */
	public DailyLog(double weight, double limit, String time)
	{
		this.weight = weight;
		this.limit = limit;
		this.time = time;
		this.intake = new HashMap<Food, Integer>();
		this.exercisesPerformed = new HashMap<Activity, Integer>();
	}
	
	/**
	 * Returns the current intake.
	 * @return The current intake. 
	 */
	public HashMap<Food, Integer> getIntake()
	{
		return this.intake;
	}
	
	/**
	 * Returns the list of activities.
	 * @return The list of activities.
	 */
	public HashMap<Activity, Integer> getActivities()
	{
		return this.exercisesPerformed;
	}
	
	/**
	 * Adds basic food/recipe to the intake along with the quantity. 
	 * @param food The Food/Recipe
	 * @param quantity The quantity of Food/Recipe
	 */
	public void addToIntake(Food food, int quantity)
	{
		if(intake.containsKey(food))
		{
			int oldQuantity = intake.get(food).intValue();
			int newQuantity = quantity + oldQuantity;
			intake.put(food, newQuantity);
		}
		else
		{
			intake.put(food, quantity);
		}
	}
	
	/**
	 * Removes the food/recipe from the intake. 
	 * @param food Food/Recipe to delete. 
	 */
	public void removeFromIntake(Food food)
	{
		if(intake.containsKey(food))
		{
			intake.remove(food);
		}
	}
	
	/**
	 * Adds activity to the list of activities along with the quantity. 
	 * @param food The activity. 
	 * @param quantity The quantity of activity. 
	 */
	public void addToActivities(Activity activity, int quantity)
	{
		if(intake.containsKey(activity))
		{
			int oldQuantity = exercisesPerformed.get(activity).intValue();
			int newQuantity = quantity + oldQuantity;
			exercisesPerformed.put(activity, newQuantity);
		}
		else
		{
			exercisesPerformed.put(activity, quantity);
		}
	}
	
	/**
	 * Removes the activity from the list of activities. 
	 * @param activity Activity to delete. 
	 */
	public void removeFromActivities(Activity activity)
	{
		if(exercisesPerformed.containsKey(activity))
		{
			exercisesPerformed.remove(activity);
		}
	}
	
	/**
	 * Gets the weight. 
	 * @return The weight. 
	 */
	public double getWeight()
	{
		return this.weight;
	}
	
	/**
	 * Sets the new weight. 
	 * @param newWeight The new weight. 
	 */
	public void setWeight(double newWeight)
	{
		this.weight = newWeight;
	}
	
	/**
	 * Gets the desired calorie limit. 
	 * @return Calorie limit. 
	 */
	public double getLimit()
	{
		return this.limit;
	}
	
	/**
	 * Sets the calorie limit. 
	 * @param newLimit New calorie limit.
	 */
	public void setLimit(double newLimit)
	{
		this.limit = newLimit;
	}
	
	/**
	 * Gets the current date of the log. 
	 * @return Date of the log. 
	 */
	public String getDate()
	{
		return this.time;
	}
	
	/**
	 * Sets the date of the log. 
	 * @param newTime New date of the log. 
	 */
	public void setDate(String newTime)
	{
		this.time = newTime;
	}
	
	/**
	 * Overridden toString() method which displays all of the information
	 * about this particular log. It displays the initial information, 
	 * list of foods/recipes, and list of exercises/workouts. 
	 */
	public String toString()
	{
		String temp = "-- Daily Log for " + this.time + " -- \n\n" + "Desired weight (lbs): " + this.weight 
						+ "\nDesired calorie limit: " + this.limit + "\n";
		Object[] foodKeys = intake.keySet().toArray();
		Object[] foodValues = intake.values().toArray();
		Object[] activityKeys = exercisesPerformed.keySet().toArray();
		Object[] activityValues = exercisesPerformed.values().toArray();
		
		temp += "\nIntake:";
		
		for(int i = 0; i < intake.size(); i++)
			temp += "\n\tFood: " + ((Food)foodKeys[i]).name + "\tQuantity: " + foodValues[i];
		
		temp += "\nActivities performed:";
		
		for(int i = 0; i < exercisesPerformed.size(); i++)
			temp += "\n\tActivity: " + ((Activity)activityKeys[i]).name + "\tQuantity: " + activityValues[i];
		
		temp += "\n-----------------------------------------\n";
		
		return temp;
	}
}
